import torch
import numpy as np


def prepraData():
    img = [[[1, 2, 3, 4, 5], [7, 8, 9, 10, 11], [12, 13, 14, 15, 16]],
           [[1, 2, 3, 4, 5], [7, 8, 9, 10, 11], [12, 13, 14, 15, 16]],
           [[1, 2, 3, 4, 5], [7, 8, 9, 10, 11], [12, 13, 14, 15, 16]],
           ]
    img = torch.tensor(img)
    print(img.shape)
    # patch = img[: , 0:imWide-40+1:40 , 0:imHigh-40+1:40]
    patch = img[:, 0:2:1, :1]

    print("pathch shape = ", patch.shape)
    print(patch)
    two = img[:, 2, 1]
    print("\ntwo shape is ", two.shape)
    print(two)
    thr = img[:, 2, :]
    print("\nthr shape is ", thr.shape)
    print(thr)
    print("\nthr shape[0] is ", thr.shape[0])
    print("\nthr shape[0] is ", thr.shape[1])
    '''
    a多维的数组，它就会被理解成两个（2x2）矩阵。
    b多维的数组，它就会被理解成两个（4x2）矩阵。
    c多维的数组，它就会被理解成一个（4x2）矩阵

    那么np.matmul(a,b)则会将a的第一个矩阵和b的第一个矩阵相乘，将a的第二个矩阵b 的第二个矩阵相乘，最终得到一个2×2×2 的结果。
    a第一个矩阵：
    [ 0  1  2  3]
    [ 4  5  6  7]
    b第一个矩阵
    [ 0  1]
    [ 2  3]
    [ 4  5]
    [ 6  7]
    相乘=[ 28  34][ 76  98]
    np.matmul(a,b)=   [[[ 28  34][ 76  98]]
                       [[428 466][604 658]]]
    
    np.matmul(a,c)的情况，由于，c只有一个矩阵，所以它会广播一个矩阵与a的第二个矩阵相乘。
    '''
    a = np.arange(2 * 2 * 4).reshape((2, 2, 4))
    b = np.arange(2 * 2 * 4).reshape((2, 4, 2))
    c = np.arange(1 * 2 * 4).reshape((1, 4, 2))
    print("a=", a)
    print("b=", b)
    print("c=", c)
    print("np.matmul(a,b)=", np.matmul(a, b))
    print("np.matmul(a,c)=", np.matmul(a, c))


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    # create()
    prepraData()